package com.huamao.niceman.scrollviewpager.information.view;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.huamao.niceman.scrollviewpager.R;
import com.huamao.niceman.scrollviewpager.base.BaseActivity;
import com.huamao.niceman.scrollviewpager.base.BaseFragment;
import com.huamao.niceman.scrollviewpager.base.BasePresent;
import com.huamao.niceman.scrollviewpager.information.adapter.ViewFlowAdapter;
import com.huamao.niceman.scrollviewpager.information.present.InformationPresent;
import com.huamao.niceman.scrollviewpager.utils.FragmentInterface;
import com.huamao.niceman.scrollviewpager.widget.ViewFlow;
import com.huamao.niceman.scrollviewpager.widget.ViewFlowCircleIndicator;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by LuanXianSheng on 2017/6/14.
 * 资讯
 */

public class InformationFragment extends BaseFragment implements FragmentInterface {
    @BindView(R.id.viewflow)
    ViewFlow mViewflow;
    @BindView(R.id.viewflowindic)
    ViewFlowCircleIndicator mIndic;
    private InformationPresent mPresent;
    private BaseActivity act;

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        act = (BaseActivity) context;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        creatPresent();
        View view = inflater.inflate(R.layout.fragment_information, null);
        ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        init();
        setData();
    }

    @Override
    public BasePresent creatPresent() {
        mPresent = new InformationPresent(this);
        return mPresent;
    }

    @Override
    public void init() {

    }

    @Override
    public void setData() {
        mViewflow.setAdapter(new ViewFlowAdapter(act));
        mViewflow.setmSideBuffer(5); // 设置图片5张
        // 轮播图的圆点
        mViewflow.setFlowIndicator(mIndic);
        mViewflow.setTimeSpan(1000);
        mViewflow.setSelection(0); // 设置初始位置
        mViewflow.startAutoFlowTimer(); // 启动自动播放
        mViewflow.computeScroll();
    }

    @Override
    public void getData(Object object) {

    }
}
